﻿using Project_Maverick.Controller.Input;
using Project_Maverick.GameRoot;
using Transformable_Engine_v2.Engine;
using Transformable_Engine_v2.Engine.Animation.PositionAnimation;
using Transformable_Engine_v2.Engine.Animation.Trajectory;
using Transformable_Engine_v2.Engine.GameObjects.Containers;
using Transformable_Engine_v2.Engine.Transformable_Math.Geometry;

namespace Project_Maverick.Screen
{
    public abstract class BaseScreen : Container
    {
        public delegate void ChangeScreenHandler(ProjectMaverick.Screen nextScreen, bool forward);
        public event ChangeScreenHandler OnChangeScreen;

        public abstract void ReceiveLocalInputPressed(PlayerInputCommand playerInputCommand);
        public abstract void ReceiveLocalInputReleased(PlayerInputCommand playerInputCommand);

        public void ChangeScreen(ProjectMaverick.Screen nextScreen, bool forward)
        {
            if (OnChangeScreen != null)
                OnChangeScreen(nextScreen, forward);
        }

        private const int TIME_FOR_TRANSITION = 1000;

        public void Enter(bool forward)
        {
            PositionGridBound = (forward ? 1 : -1) * new TE_Vector2(48 + 27f/Game.Options.GridSize, 0);
            AddAnimations(new PositionAnimation(new QuadraticEasing(BaseTrajectory.Easing.EaseInAndOut), TE_Vector2.Zero, TIME_FOR_TRANSITION, false, 0));
        }

        public virtual void Exit(bool forward)
        {
            var exitPosition = (forward ? -1 : 1) * new TE_Vector2(48 + 27f / Game.Options.GridSize, 0);
            AddAnimations(new PositionAnimation(new QuadraticEasing(BaseTrajectory.Easing.EaseInAndOut), exitPosition, TIME_FOR_TRANSITION, false, 0));
        }
    }
}